// src/stores/chat.js
import { defineStore } from 'pinia'
import { ref } from 'vue'
// 用于联系人跳转聊天页面存储的用户信息
export const useChatStore = defineStore('chat', () => {
  const targetUser = ref(null) // 用于保存要聊天的用户

  // 设置要聊天的用户
  const setTargetUser = (user) => {
    targetUser.value = user
  }

  // 清除要聊天的用户
  const clearTargetUser = () => {
    targetUser.value = null
  }

  return {
    targetUser,
    setTargetUser,
    clearTargetUser
  }
}, {
  persist: {
    key: 'user-chat', // 存储的键名，默认是store的id
    storage: localStorage, // 存储方式，默认是localStorage
    paths: ['targetUser'] // 指定要持久化的状态路径
  }
})
